// 预约登记 状态管理
import Vue from 'vue';

export const state = Vue.observable({
  packageBaseRules: [], // 套餐基础规则
  packageCarDetail: [], // 套餐车辆明细
  packageType: 'add',
  // defaultRepair: '', //默认的维修类型
  // isDisabled: true, //控制输入框
  // ownerCarObject: {}, // 车主车辆的信息
  packageJxxmList: [], // 交修项目数据
  // jxxmChang: {}, //交修项目数据变化
  packageWxgsList: [], // 维修工时数据
  packageWxljList: [], // 维修配件数据
  packageAddItemList: [], // 附加项目数据
  packageWxgjList: [], // 维修工具数据
  packageGsList:[],

  packageBaseRulesDelete: [], // 套餐基础规则删除数据
  packageCarDetailDelete: [], // 套餐车辆明细删除数据
  packageJxxmListDelete: [], // 交修项目删除数据
  packageWxgsListDelete: [], // 维修工时删除数据
  packageWxljListDelete: [], // 维修配件删除数据
  packageAddItemListDelete: [], // 附加项目删除数据
  packagewxgjListDelete: [], // 维修工具删除数据
  // onSelectJxxmlist: [], //交修项目选中的数据
  // deleteSetCode: [], // 删除套餐
  // deleteJxxm: 0, // 删除交修项目
  // typeIdList: [], // 内结说明
  // repairCategoryCode: '', //维修类型
  packageFwtc: null,
  // relationWxlj: [], //工时关联配件
  // routeSource: '', //路由来源
  packageAllMoney: {
    gs: 0,
    lj: 0,
    fj: 0,
    jl: 0,
    gl: 0,
    fl:0
  }
});

export const mutations = {
  setPackageType: data => {
    state.packageType = data;
    if (data === 'add') {
      state.packageAllMoney = {
        gs: 0,
        lj: 0,
        fj: 0,
        jl: 0,
        gl: 0,
        fl:0
      };
      state.packageFwtc = null;
      for (const k in state) {
        if (Object.prototype.toString.call(state[k]) === '[object Array]') {
          state[k] = [];
        }
      }
    }
  },

  setPackageBaseRules: data => (state.packageBaseRules = data),
  setPackageCarDetail: data => (state.packageCarDetail = data),
  setDefaultRepair: data => (state.defaultRepair = data),
  setAllMoney: data => (state.packageAllMoney = data),
  setFwtcFn: data => (state.packageFwtc = data),
  // setIsDisabled: isDisabled => (state.isDisabled = isDisabled),
  // setOwnerCarObject: ownerCarObject => (state.ownerCarObject = ownerCarObject),
  setJxxmList: packageJxxmList => (state.packageJxxmList = packageJxxmList),
  // setJxxmChange: jxxmChang => (state.jxxmChang = jxxmChang),
  setPackageWxgsList: packageWxgsList => (state.packageWxgsList = packageWxgsList),
  setPackageWxljList: packageWxljList => (state.packageWxljList = packageWxljList),
  setPackageAddItemList: packageAddItemList => (state.packageAddItemList = packageAddItemList),
  setPackageWxgjList: packageWxgjList => (state.packageWxgjList = packageWxgjList),
  setPackageGsList:packageGsList => (state.packageGsList = packageGsList),

  setPackageBaseRulesDelete: data => (state.packageBaseRulesDelete = data),
  setPackageCarDetailDelete: data => (state.packageCarDetailDelete = data),

  setJxxmListDelete: packageJxxmListDelete => (state.packageJxxmListDelete = packageJxxmListDelete),
  setWxgsListDelete: packageWxgsListDelete => (state.packageWxgsListDelete = packageWxgsListDelete),
  setWxljListDelete: packageWxljListDelete => (state.packageWxljListDelete = packageWxljListDelete),
  setAddItemListDelete: packageAddItemListDelete => (state.packageAddItemListDelete = packageAddItemListDelete),
  setWxgjListDelete: packagewxgjListDelete => (state.packagewxgjListDelete = packagewxgjListDelete),
  // setOnSelectJxxmList: onSelectJxxmlist => (state.onSelectJxxmlist = onSelectJxxmlist),
  setDeleteSetCode: deleteSetCode => (state.deleteSetCode = deleteSetCode),
  setDeleteJxxm: deleteJxxm => (state.deleteJxxm = deleteJxxm)
  // setTypeIdList: typeIdList => (state.typeIdList = typeIdList),
  // setRepairCategoryCode: repairCategoryCode => (state.repairCategoryCode = repairCategoryCode),
  // setRouteSource: routeSource => (state.routeSource = routeSource),
  // setRelationWxlj: relationWxlj => (state.relationWxlj = relationWxlj),
  // cancelState: () => {
  //   for (let k in state) {
  //     if (Object.prototype.toString.call(state[k]) === '[object Array]') {
  //       if (k !== 'typeIdList') {
  //         state[k] = [];
  //       }
  //     } else if (Object.prototype.toString.call(state[k]) === '[object Object]') {
  //       if (k == 'packageallMoney') {
  //         state[k] = {
  //           gs: 0,
  //           lj: 0,
  //           fj: 0
  //         }
  //       } else {
  //         state[k] = {};
  //       }

  //     } else if (Object.prototype.toString.call(state[k]) === '[object String]') {
  //       if (k !== 'defaultRepair' && k !== 'repairCategoryCode') {
  //         state[k] = '';
  //       }

  //     } else if (Object.prototype.toString.call(state[k]) === '[object Boolean]') {
  //       state[k] = true;
  //     } else if (Object.prototype.toString.call(state[k]) === '[object Number]') {
  //       state[k] = 0;
  //     } else {
  //       state[k] = null;
  //     }
  //   }
  //   console.log(state, '------this.state')

  // }
};
